/*

示例

{
    "id": "test",
    "type": "HeadView",
    "leftWord":"左边",
    "rightWord":"右边",
    "leftIcon": "icon-back",
    "rightIcon": "icon-right",
    "titleName":"标题名称"
    }
*/
define(['./BaseView', 'jquery'], (BaseView, $)=> {
    require('../../less/header.less');

    return BaseView.extend({
        type: "NoCloseHeadView",
        events:{
            'click .left':'back',
            'click .close-window': 'close'
        },
        back:function () {
            Backbone.history.history.back();
        },
        close: function () {
            var data = {
                function: 'closePage'
            };
            window.WebViewJavascriptBridge.send(JSON.stringify(data), function(res) {});
        },
        initialize:function () {
            var me = this;
        },
        render: function() {
            let lt = this.options.leftIcon;
            let rt = this.options.rightIcon;
            let nPage = this.currentPage.id;
            //let closeWord = this.options.closeWord || '关闭';
            //let closeStyle = nPage !== window.app.defaultPage ? '"display: table"' : '"display: none"';
            let leftWord = this.options.leftWord ? this.options.leftWord : '';
            let rightWord = this.options.rightWord ? this.options.rightWord : '' ;
            let leftIcon = this.options.leftIcon ? '<i class="'+ lt +'"></i>' : '<i class="icon-back"></i>';
            let rightIcon = this.options.rightIcon ? '<i class="'+ rt +'"></i>' : '';
            let html=`<div class="headview">
                <div class="left">
                    ${leftIcon}
                    <span>${leftWord}</span>
                </div>
                 <h1 class="title">${this.options.titleName}</h1>
                <div class="right">
                    <span>${rightWord}</span>
                    ${rightIcon}
                    </div>
            </div>`;
            this.$el.append(html);
            return this;
        },

    });

});
